import { createRouter, createWebHistory } from 'vue-router'
import Dashboard from '../views/Dashboard.vue'
import Tables from '../views/Tables.vue'
import DataManagement from '../views/DataManagement.vue'

const routes = [
  {
    path: '/',
    name: 'Dashboard',
    component: Dashboard,
    meta: { title: '首页' }
  },
  {
    path: '/tables',
    name: 'Tables',
    component: Tables,
    meta: { title: '表页' }
  },
  {
    path: '/data/:tableName',
    name: 'DataManagement',
    component: DataManagement,
    props: true,
    meta: { title: '编辑页' }
  },
  // 首页进入编辑后的页面
  {
  path: '/edit',
  name: 'EditPage',
  component: () => import('../views/EditPage.vue'),
  meta: { title: '分类页' }
  },
  //让页面支持动态路由参数，比如：/data/:tableName
  {
  path: '/data/:tableName',
  name: 'DataManagement',
  component: () => import('@/views/DataManagement.vue'),
  meta: { title: '编辑页' }
},
// 用户手册页面
{
  path: '/user',
  name: 'UserManual',
  component: () => import('../views/UserManual.vue'),
  meta: { title: '用户手册' }
}
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title ? `${to.meta.title} - 信息录入系统` : '信息录入系统'
  next()
})

export default router